/**
 * The main application class. An instance of this class is created by app.js when it
 * calls Ext.application(). This is the ideal place to handle application launch and
 * initialization details.
 */
Ext.define('OrderConvert.Application', {
    extend: 'Ext.app.Application',
    
    name: 'OrderConvert',

    stores: [
        // TODO: add global / shared stores here
    ],
    
    launch: function () {
        layer.closeAll('loading');

        var user = Ext.util.Cookies.get("userId");
        if(!user){
            var widget = Ext.widget("logintwin");
            widget.show();
        }

        // Ext.Ajax.request({
        //     url: 'http://108.118.5.177:8080/sumeccore/services/getToken?APPID=22ce7e29-0b67-49e2-9e3b-1d91033f6c05&APPSECRET=5DB72FC79BF53BFFC517B9681C3D60BAAEDA410A3E90AF9C55DE215EB6E92C7D056431FF61AE1BEDEC82D319165DC283ED1A603E724A23193400E30312370F2D',
        //     success: function(response, opts) {
        //         var obj = Ext.decode(response.responseText);
        //         Ext.util.Cookies.set("token",obj.data);
        //         Ext.Ajax.request({
        //             method:'POST',
        //             url: 'http://108.118.5.177:8080/sumeccore/services/SUM_login2',
        //             // url: 'http://108.118.5.177:8080/serviceprovider/sumec/login2',
        //             params : {
        //                 TOKEN : obj.data,
        //                 APPID : "22ce7e29-0b67-49e2-9e3b-1d91033f6c05",
        //                 APPSECRET : "5DB72FC79BF53BFFC517B9681C3D60BAAEDA410A3E90AF9C55DE215EB6E92C7D056431FF61AE1BEDEC82D319165DC283ED1A603E724A23193400E30312370F2D",
        //                 LOGID : "HD",
        //                 LOGPWD : "Fabc1"
        //             },
        //             success: function(response, opts) {
        //                 var obj = Ext.decode(response.responseText);
        //                 if(obj){
        //                     var data = obj.data;
        //                     var userId = data.userId;
        //                     var userName = data.userName;
        //                     var userOrg = data.userOrg;
        //                     var orgNo = null;
        //                     if(userOrg != null && userOrg.length > 0){
        //                         orgNo = userOrg[0].longOrgId;
        //                     }
        //                     Ext.util.Cookies.set("userId",userId);
        //                     Ext.util.Cookies.set("userName",userName);
        //                     Ext.util.Cookies.set("orgNo",orgNo);
        //                 }
        //             },
        //
        //             failure: function(response, opts) {
        //                 console.log('server-side failure with status code ' + response.status);
        //             }
        //         });
        //     },
        //
        //     failure: function(response, opts) {
        //         console.log('server-side failure with status code ' + response.status);
        //     }
        // });
    },

    onAppUpdate: function () {
        window.location.reload();
    }
});
